import cookie from 'react-cookies';

// 获取当前用户cookie
export const getCookies = () => {
  return {
    userid: cookie.load('userid'),
    username: cookie.load('username'),
    group: cookie.load('group'),
    roll: cookie.load('roll'),
    token: cookie.load('userToken')
  }
}

// 用户登录，保存cookie
export const setCookies = (userid, username, group, roll, token) => {
  cookie.save('userid', userid, { path: '/' });
  cookie.save('username', username, { path: '/' });
  cookie.save('group', group, { path: '/' });
  cookie.save('roll', roll, { path: '/' });
  cookie.save('userToken', token, { path: '/' });
}

// 用户登出，删除cookie
export const deleteCookie = () => {
  cookie.remove('userid');
  cookie.remove('username');
  cookie.remove('group');
  cookie.remove('roll');
  cookie.remove('userToken');
  window.location.href = '/Login';
}
